-
-
Notifications
You must be signed in to change notification settings - Fork 9k
支持一个商户号配置多个小程序appId #3849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
支持一个商户号配置多个小程序appId #3849
Conversation
Co-authored-by: binarywang <[email protected]>
Co-authored-by: binarywang <[email protected]>
🤖 Augment PR Summary总结:本 PR 为 wx-pay 多配置场景补充“仅按商户号(mchId)切换配置”的能力,以支持同一商户号绑定多个小程序 appId 的业务。 主要变更:
技术要点:切换仍基于 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...in-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
Show resolved
Hide resolved
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
Outdated
Show resolved
Hide resolved
...y/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverManualTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
这个 Pull Request 为 weixin-java-pay 模块添加了支持一个商户号配置多个小程序 appId 的功能。该功能解决了当前只能通过 mchId + appId 组合切换配置的限制,新增了仅使用商户号进行切换的 API。
Changes:
- 在
WxPayService接口中新增了两个重载方法:switchover(String mchId)和switchoverTo(String mchId) - 在
BaseWxPayServiceImpl中实现了这两个方法,使用精确匹配和前缀匹配策略查找配置 - 添加了完整的单元测试覆盖新功能的各种场景
- 提供了详细的使用文档,说明配置方式、使用场景和注意事项
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java | 新增两个仅使用商户号切换配置的接口方法 |
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java | 实现新增的两个方法,使用精确匹配和前缀匹配逻辑查找配置 |
| weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverTest.java | 添加全面的单元测试,覆盖新功能的各种使用场景 |
| weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverManualTest.java | 提供手动测试类,用于验证功能的正确性 |
| weixin-java-pay/MULTI_APPID_USAGE.md | 新增详细的使用文档,包含配置示例、使用场景和最佳实践 |
...in-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
Show resolved
Hide resolved
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
Outdated
Show resolved
Hide resolved
...ava-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverTest.java
Outdated
Show resolved
Hide resolved
...ava-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverTest.java
Show resolved
Hide resolved
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
Outdated
Show resolved
Hide resolved
...in-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
Show resolved
Hide resolved
...in-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
bbc138a to
30914f3
Compare
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ice/impl/MultiAppIdSwitchoverTest.java Co-authored-by: Copilot <[email protected]>
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: binarywang <[email protected]>
1. 为接口方法 switchover(String mchId) 和 switchoverTo(String mchId) 添加 default 实现,保证向后兼容 2. 将手动测试中的 Java assert 替换为显式 verify() 方法,避免断言不生效的问题
功能说明
解决了 wx-pay 无法灵活支持一个商户号对应多个小程序 appId 的问题。
问题分析
当前限制:
mchId + "_" + appId作为配置的唯一标识switchover(mchId, appId)精确切换,不够灵活业务场景:
解决方案
采用向后兼容的增强方案,支持仅通过商户号(mchId)进行配置切换。
主要改动
1. 新增 API 方法(WxPayService.java)
boolean switchover(String mchId)- 仅使用商户号切换配置WxPayService switchoverTo(String mchId)- 仅使用商户号切换(支持链式调用)2. 实现配置查找逻辑(BaseWxPayServiceImpl.java)
mchId_*3. 改进文档注释
4. 增强测试用例
5. 保持向后兼容
switchover(mchId, appId)方法保持不变代码审查反馈已处理
使用示例
配置多个 appId:
方式1:精确切换(推荐,确定性行为)
方式2:仅商户号切换(新功能,注意不确定性)
方式3:链式调用
测试验证
文档
详细使用文档:
weixin-java-pay/MULTI_APPID_USAGE.md包含:
检查清单
补充说明
WxPayConfigHolder(基于ThreadLocal),是线程安全的Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.